;;; This is the IDE's built-in-editor, where you create and edit
;;; lisp source code.  You could use some other editor instead,
;;; though the IDE's menu-bar commands would not be applicable there.
;;; 
;;; This editor has a tab for each file that it's editing.  You can
;;; create a new editor buffer at any time with the File | New command.
;;; Other commands such as Search | Find Definitions will create
;;; editor buffers automatically for existing code.
;;; 
;;; You can use the File | Compile and Load command to compile and
;;; load an entire file, or compile an individual definition by
;;; placing the text cursor inside it and using Tools | Incremental
;;; Compile.  You can similarly evaluate test expressions in the
;;; editor by using Tools | Incremental Evaluation; the returned
;;; values and any printed output will appear in a lisp listener
;;; in the Debug Window.
;;; 
;;; For a brief introduction to other IDE tools, try the
;;; Help | Interactive IDE Intro command.  And be sure to explore
;;; the other facilities on the Help menu.


(defpackage :r-run
  (:use :common-lisp)
  (:export :lbd :b-day :pf :newton :fact))

(in-package :r-run)

(defclass file-info ()
  (
   (file-name)
   
   )
  
  )

(defvar *location-of-r* "D:\\Program Files\\R\\R-2.9.1\\bin\\r.exe")
(defvar *location-of-rgui* "D:\\Program Files\\R\\R-2.9.1\\bin\\rgui.exe")
(defvar *directory-of-r* "D:\\Program Files\\R\\R-2.9.1\\bin")
(defvar *script-dir-r* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\haxe\\R\\R\\scripts")
(defvar *rpn* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\README\\rpn\\rpn.exe")
(defvar *directory-of-rpn* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\README\\rpn")
(defvar *location-of-ttp* "D:\\Program Files\\Seapine\\TestTrack\\TestTrack Client.exe")
(defvar *directory-of-ttp* "D:\\Program Files\\Seapine\\TestTrack")
(defvar *location-of-readings* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\haxe\\R\\R\\hmi\\reading.xlsx")
(defvar *directory-of-readings* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\haxe\\R\\R\\hmi")
(defvar *location-of-readings-output* "D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\haxe\\R\\R\\scripts\\Rplots.pdf")
(defvar *location-of-excel* "C:\\Program Files\\Microsoft Office\\Office12\\excel.exe")



(defun do-run (run-me &key d (w nil))
  (if d 
      (common-graphics-user::run-shell-command run-me :directory d :wait w :if-input-does-not-exist nil)
      (common-graphics-user::run-shell-command run-me :wait w :if-input-does-not-exist nil)
    )
  )

(defun xl (n)
  (let* 
      (
       ( x (format nil "~a ~a" *location-of-excel* n))
       )
    (do-run x)
    ))

(defun do-run-file (run-me &key d (w nil))
  ( let*
      (
       (r (format nil "explorer ~a" run-me))
       )
    (do-run r :d d :w w)
    
    )
  )


(defun run-r (n)
  (let*
      (
       (the-command-line (format nil "~a CMD BATCH ~a" *location-of-r* n))
       )
    
  
    (do-run the-command-line :d *directory-of-r*)
    )
  )

(defmacro r-batch (file-name)
  `(let ( (cmd (format nil "r --vanilla <~a >d:\\r\\silly.txt" ,file-name)))
     (common-graphics-user::run-shell-command cmd :directory *script-dir-r*)
     ))


(defun r-test ()
  (common-graphics-user::run-shell-command "r --vanilla <reading.r >silly.txt"
                                           :directory *script-dir-r*)
  
  (common-graphics-user::run-shell-command "explorer D:\\Documents and Settings\\abbottpm\\My Documents\\CopyOfS\\haxe\\R\\R\\scripts\\Rplots.pdf"
                                           :directory *script-dir-r*)
  
  )

(defvar silly-01 "http://extranet-sharepoint.ingerrand.com/cctech/sr2controlsys/_layouts/listedit.aspx?List={7924B61E-33FF-4634-BFF5-7AA1662AD620}")



(defvar silly-02 "http://extranet-sharepoint.ingerrand.com/cctech/etgext/Product%20HardwareDesign%20Documentation/Forms/AllItems.aspx?RootFolder=%2fcctech%2fetgext%2fProduct%20HardwareDesign%20Documentation%2fSR3&FolderCTID=&View=%7b61583953%2dEE64%2d4291%2d915F%2d20E9033AF932%7d>")



(defun counter-class ()
  (let ( (counter 0) )
    (lambda () (incf counter))))


(defmacro str-cat (a b) `(format nil "~a~a" ,a ,b))

(defun argh () 
  (do-run (str-cat "explorer " *directory-of-r*) :d *directory-of-r*)
  )

(defmacro explore-directory (d) 
  `(do-run (str-cat "explorer " ,d) :d ,d)
  )


(defun e-d ()
  (if 
      (y-or-n-p "R")
      (explore-directory *directory-of-r*)
    (explore-directory (read-line))
    )
  )

(defun some-r-thing (source-file &optional (target-file "silly.txt"))
  (let*
      (
       (the-command-line (format nil "R --vanilla <~a >~a" source-file target-file))
       )
    (format t the-command-line :d *directory-of-r*)
    (do-run the-command-line )
    ; (do-run "explorer D:\\Program Files\\R\\R-2.9.1\\bin\\Rplots.pdf")
    )
  
  )

(defmacro r () `(do-run *location-of-rgui*))
(defmacro reading ()
  `(explore-directory *location-of-readings*)
  (do-run-file *location-of-readings*)
  (r-batch "reading.r")
  (do-run-file *location-of-readings-output*)
  )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defmacro issue-page (n) 
  `(format nil "http://extranet-sharepoint.ingerrand.com/cctech/sr2controlsys/Lists/SR2%20ST%20Truck/DispForm.aspx?ID=~a" ,n))

(defmacro issue (n) 
  `(explore-directory (issue-page ,n)))


        
  

